﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QXBook.Controls.ServerControls
{
    public enum DisplayType
    {
        Label,
        TextBox
    };

    public class TextBoxLabel : Control, IAttributeAccessor
    {
        public string Text
        {
            get
            {
                string s = (string)ViewState["Text"];
                return ((s == null) ? string.Empty : s);
            }
            set
            {
                ViewState["Text"] = value;
            }
        }

        protected override void Render(HtmlTextWriter output)
        {
            string strTag = ControlDisplayType == DisplayType.Label ? string.Empty : "<input name=\"i" + this.ClientID + " type=\"text\" " + this.Attributes + " value=\"{0}\" />";
            output.Write(!string.IsNullOrEmpty(strTag) ? Text : string.Format(strTag, Text));
        }

        string IAttributeAccessor.GetAttribute(string name)
        {
            return this.Attributes[name];
        }

        void IAttributeAccessor.SetAttribute(string name, string value)
        {
            this.Attributes[name] = value;
        }

        public QXBook.Controls.AttributeCollection Attributes
        {
            get
            {
                if (this._attrColl == null)
                {
                    this._attrColl = new QXBook.Controls.AttributeCollection();
                }
                return this._attrColl;
            }
        }

        public DisplayType ControlDisplayType
        {
            get
            {
                DisplayType d = (DisplayType)ViewState["ControlDisplayType"];
                return ((d == null) ? DisplayType.Label : d);
            }

            set
            {
                ViewState["ControlDisplayType"] = value;
            }
        }

        private QXBook.Controls.AttributeCollection _attrColl;
    }
}
